package com.example.demo.service.imply;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.mapper.QuestionBankMapper;
import com.example.demo.mapper.QuestionCategoryMapper;
import com.example.demo.mapper.QuestionClassificationMapper;
import com.example.demo.mapper.QuestionLabelMapper;
import com.example.demo.pojo.entity.QuestionCategory;
import com.example.demo.pojo.vo.QuestionCategoryVO;
import com.example.demo.pojo.vo.QuestionVO;
import com.example.demo.service.ICategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
public class ICategoryServiceImply extends ServiceImpl<QuestionCategoryMapper, QuestionCategory> implements ICategoryService {
    private final QuestionBankMapper questionBankMapper;
    private final QuestionClassificationMapper questionClassificationMapper;
    private final QuestionLabelMapper questionLabelMapper;
    private final QuestionCategoryMapper questionCategoryMapper;
    @Override
    public List<QuestionCategoryVO> initCategoryList() {
        List<QuestionCategoryVO>result=new ArrayList<>();
        List<QuestionCategory>categoryList=questionCategoryMapper.initQuestionCategory();
        for (QuestionCategory questionCategory : categoryList) {
            QuestionCategoryVO questionCategoryVO = new QuestionCategoryVO();
            questionCategoryVO.initVO(questionCategory);
            int categoryId = questionCategory.getId();
            int number = questionBankMapper.getCountByCategoryId(categoryId);
            questionCategoryVO.setNumber(number);
            result.add(questionCategoryVO);
        }
        return result;
    }
}
